package com.hrp.service;

import com.hrp.domain.Jjfact;
import com.hrp.domain.Jxkhzb;
import com.hrp.domain.Jxksgsmb;
import com.hrp.hrpdao.JjfactDao;
import com.hrp.hrpdao.JxkhzbDao;
import com.hrp.hrpdao.JxksgsmbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Administrator on 2018/8/13 0013.
 */
@Service
public class JxksgsmbService {


    @Autowired
    private JxkhzbDao jxkhzbDao;

    @Autowired
    private JxksgsmbDao jxksgsmbDao;

    @Autowired
    private JjfactDao jjfactDao;

    public boolean updateGsmb(String gsmb,String jxksdm,String jxksmc,String gsmcHtml){
        String[] gsarr= gsmb.split(",");
        StringBuilder actureGs = new StringBuilder();
        StringBuilder factGs = new StringBuilder();
        try{
            for(int i=0 ;i<gsarr.length;i++){
                Jjfact jjfact = jjfactDao.getJjfactByJjzbmc(gsarr[i]);
                if(jjfact==null){
                    actureGs.append(gsarr[i]);
                    factGs.append(gsarr[i]);
                }else{
                    actureGs.append(jjfact.getJjmc());
                    factGs.append(jjfact.getJjmcpy());
                }
            }

            Date date = new Date();
            Jxksgsmb jxksgsmb = new Jxksgsmb();

            jxksgsmb.setGsmb(factGs.toString());
            jxksgsmb.setGsmc(actureGs.toString());
            jxksgsmb.setGsmcHtml(gsmcHtml);
            jxksgsmb.setJxksdm(jxksdm);
            jxksgsmb.setJxksmc(jxksmc);
            jxksgsmb.setInsertdate(date);
            jxksgsmb.setUpdatedate(date);

            Jxksgsmb jxksgsmb1 = jxksgsmbDao.getJxksgsmbByJxksdm(jxksdm);
            if(jxksgsmb1!=null){
                jxksgsmbDao.updateJxksgsmbByJxksdm(jxksgsmb);
            }else{
                Integer inti = jxksgsmbDao.add(jxksgsmb);
            }
            return false;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }


    public Jxksgsmb getJxksgsmbByJxksdm(String jxksdm){
        return jxksgsmbDao.getJxksgsmbByJxksdm(jxksdm);
    }

}
